package com.geotmt.billingcenter.modules.statis.controller;

import com.geotmt.billingcenter.common.result.ResponseResult;
import com.geotmt.billingcenter.common.vo.consume.ConsumeStatisVo;
import com.geotmt.billingcenter.common.vo.params.PageOrgFilter;
import com.geotmt.billingcenter.common.vo.params.ParamsConsume;
import com.geotmt.billingcenter.modules.statis.service.ConsumeStatisService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 消耗统计
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/27 18:04
 * @Version     v1
 **/
@Api(value = "消耗统计接口",tags = "消耗统计接口")
@RestController
@RequestMapping(value = "/bc/consumeStatis")
public class ConsumeStatisController extends PageOrgFilter {

    private static final Logger logger = LoggerFactory.getLogger(ConsumeStatisController.class);

    @Resource
    private ConsumeStatisService consumeStatisService;

    /**
     * 消耗统计
     * @return
     */
    @ApiOperation(value = "消耗统计")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public ResponseResult consumeStatis(@RequestBody ParamsConsume obj){
        logger.info("消耗统计,ParamsConsume:{}",obj);
        Map<String,Object> repMap = new HashMap<>(2);
        try{
            this.filterPage(obj,"t1.day_flag desc");
            if(null == obj.getEffectStartTime() || null == obj.getEffectEndTime()){
                return ResponseResult.build(HttpServletResponse.SC_NOT_ACCEPTABLE,"开始时间和结束时间不能为空！",null,false);
            }
            PageInfo<ConsumeStatisVo> page = new PageInfo<>(consumeStatisService.consumeStatisList(obj));
            ConsumeStatisVo consumeStatisVo = consumeStatisService.consumeStatisTotal(obj);
            repMap.put("page",page);
            repMap.put("totalObj",consumeStatisVo);

        }catch (Exception e) {
            e.printStackTrace();
            logger.error("消耗统计,Exception:",e);
            return ResponseResult.error("查询失败");
        }
        return ResponseResult.build(HttpServletResponse.SC_OK,"查询成功",repMap,true);
    }

}